package com.flot.yazb.home.moudle;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.flot.yazb.R;
import com.flot.yazb.base.BApplication;
import com.flot.yazb.base.BFragment;
import com.flot.yazb.model.user.UserModel;
import com.flot.yazb.home.linemoudle.HotFragment;
import com.flot.yazb.home.linemoudle.LineNearlyFragment;
import com.flot.yazb.home.linemoudle.OneToOneFragment;
import com.flot.yazb.home.linemoudle.PrivateFragment;
import com.flot.yazb.home.setting.PayVipActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class LineFragment extends BFragment {
    @BindView(R.id.tv_1)
    TextView tv1;
    @BindView(R.id.tv_2)
    TextView tv2;
    @BindView(R.id.tv_3)
    TextView tv3;
    @BindView(R.id.tv_4)
    TextView tv4;
    @BindView(R.id.line_1)
    TextView line_1;
    @BindView(R.id.line_2)
    TextView line_2;
    @BindView(R.id.line_3)
    TextView line_3;
    @BindView(R.id.line_4)
    TextView line_4;
    @BindView(R.id.innercontain)
    FrameLayout innercontain;

    private View view;
    private UserModel argsModel;
    private HotFragment hf = HotFragment.newInstance(BApplication.getInstance().getUserModel());
    private PrivateFragment pf = PrivateFragment.newInstance(BApplication.getInstance().getUserModel());
    private LineNearlyFragment lf = LineNearlyFragment.newInstance(BApplication.getInstance().getUserModel());
    private OneToOneFragment of = OneToOneFragment.newInstance(BApplication.getInstance().getUserModel());

    @Override
    protected View initRootView(LayoutInflater inflater) {
        if (view == null) {
            view = View.inflate(getActivity(), R.layout.fragment_home_line, null);
        }
        ButterKnife.bind(this, view);
        ViewGroup myparent = (ViewGroup) view.getParent();
        if (getArguments() != null) {
            argsModel = (UserModel) getArguments().getSerializable("args");
        }
        if (myparent != null) {
            myparent.removeView(view);
        }
        return view;
    }

    //利用setArgues传递参数
    public static LineFragment newInstance(UserModel model) {
        LineFragment fragment = new LineFragment();
        Bundle args = new Bundle();
        args.putSerializable("args", model);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void initView() {
        //默认进入热门页面
       replaceFragment(R.id.innercontain, hf);
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @OnClick({R.id.ll_1, R.id.ll_2, R.id.ll_3, R.id.ll_4,R.id.iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_1:
                replaceFragment(R.id.innercontain, hf);
                line_1.setVisibility(View.VISIBLE);
                line_2.setVisibility(View.INVISIBLE);
                line_3.setVisibility(View.INVISIBLE);
                line_4.setVisibility(View.INVISIBLE);
                break;
            case R.id.ll_2:
                replaceFragment(R.id.innercontain, pf);
                line_1.setVisibility(View.INVISIBLE);
                line_2.setVisibility(View.VISIBLE);
                line_3.setVisibility(View.INVISIBLE);
                line_4.setVisibility(View.INVISIBLE);
                break;
            case R.id.ll_3:
                replaceFragment(R.id.innercontain, lf);
                line_1.setVisibility(View.INVISIBLE);
                line_2.setVisibility(View.INVISIBLE);
                line_3.setVisibility(View.VISIBLE);
                line_4.setVisibility(View.INVISIBLE);
                break;
            case R.id.ll_4:
                replaceFragment(R.id.innercontain, of);
                line_1.setVisibility(View.INVISIBLE);
                line_2.setVisibility(View.INVISIBLE);
                line_3.setVisibility(View.INVISIBLE);
                line_4.setVisibility(View.VISIBLE);
                break;
            case R.id.iv_back:
                Intent intent3= new Intent(getActivity(),PayVipActivity.class) ;
                startActivity(intent3);
                break;
        }
    }
}
